#ifndef DATACONTAINER_H
#define DATACONTAINER_H


#include "datasuite_global.h"
#include "metadata.h"


#include <abstractmodelitem.h>

#include <QObject>
#include <QSharedData>
#include <QSharedDataPointer>
#include <QPointer>
#include <qvariant.h>


class DataSuite;


class DATASUITESHARED_EXPORT DataContainer : public AbstractModelItem
{
    Q_OBJECT

    class Data : public QSharedData
    {
    public:

        Data() {}
        Data(const Data& other) : QSharedData(other)
        {
            name = other.name;
        }

        QString name;
    };

    Q_PROPERTY(QString name READ name WRITE setName)


public:

//    enum Field
//    {
//        Field_FIRST = 0,
//        Field_NAME = Field_FIRST,
//        Field_LAST = Field_NAME
//    };


    Q_INVOKABLE DataContainer(DataSuite *parent = 0);
    DataContainer(const DataContainer& other);

    virtual int internalFieldCount() const;

    virtual int fieldCount() const;
    virtual QVariant value(int field, int role) const;
    virtual bool setValue(int field, const QVariant &value, int role);
    virtual QVariant fieldName(int field) const;

    bool setFieldName(int field, const QString& name);
    void addField(const QString& name);
    
    QString name() const;
    void setName(const QString& name);

    QList<DataContainer*> childData() const;

    QString objectPath() const;


protected:

    virtual MetaData* metaData() const;


    QString metaPropertyName(int field) const;
    QVariant metaPropertyValue(int field) const;
    bool setMetaPropertyValue(int field, const QVariant& value);

private:

    QSharedDataPointer<Data> d;

    friend class DataSuite;

};


Q_DECLARE_METATYPE(DataContainer*)


#endif // DATACONTAINER_H
